package club.xshiwu.springcloud.controller;

import club.xshiwu.springcloud.pojo.CommonResult;
import club.xshiwu.springcloud.pojo.Order;
import club.xshiwu.springcloud.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by Intellij IDEA.
 * User:  xsw
 * Date:  2020/6/12
 */
@RestController
public class OrderController {
    @Resource
    private OrderService orderService;

    /**
     * 从Order实体获取创建得订单微服务
     * @param order
     * @return
     */
    @GlobalTransactional(name = "fsp-create-order",rollbackFor = Exception.class) //此注解开启全局事务
    @GetMapping("/order/create")
    public CommonResult create(Order order){
        orderService.create(order);
        return new CommonResult(200, "订单创建成功！O(∩_∩)O");
    }
}
